<?php
/**
 * 
 * @version : 1.0
 * @since June-2008
 * @deprecated  Lớp cơ bản CXMLCategory
 * @package : lib/cache
*/
/**
 * Định nghĩa một số hàm dùng chung cho lớp CXmlCategory
 *
 */
class CXmlCategory
{
	public $xmlFile;
	function __construct($xmlFile)
	{
		$this->xmlFile	 = $xmlFile;
	}
	
	/**
	 * @example : 
	 * CXmlCategory($xmlpath)->get_cat_path('cats/cat','news');
	 *
	 * @param string $basic_path
	 * @param string $category_id
	 */
	function get_cat_path(&$result, $cat_xpath = '', $category_id = ''){
		if(!empty($category_id)){
			return CStoreCategoryList::getInstance()->getCatePath($category_id, $result);
			/*
			$xmlObj = new CDataXmlStore($this->xmlFile, '/root/');
			$detail = $xmlObj->select_parent($cat_xpath."[./id='$category_id']");
			if($detail['id'] == 'root'){
				return $result;
			}else {
				return $this->get_cat_path($result, $cat_xpath,$detail['id']);
			}
			*/
		}else {
			return false;
		}
	}
	
	function get_all_categories(){
		$categories = $this->normalize(CTable('cats/cat/cats/cat/id | cats/cat/cats/cat/name')->change_store(new CDataXmlStore($this->xmlFile))->select_all());
		if(!empty($categories)){
			foreach ($categories as &$category){
				$id = $category['id'];
				$category['childs'] = CTable("cats/cat/cats/cat[./id='$id']/cats/cat")->change_store(new CDataXmlStore($this->xmlFile))->select_all();
			}
		}
		return $categories;
	}
	
	function normalize($perform_array){
		for($i =0; $i<count($perform_array)/2; $i++){
			$result[$i]['id'] = $perform_array[2*$i];
			$result[$i]['name'] = $perform_array[2*$i+1];
		}
		return $result;
	}
    
}//end Class

function CXmlCategory($xmlFile)
{
	return new CXmlCategory($xmlFile);
}


?>